#include "mainwindow.h"
#include "downloadview.h"
#include "newtaskdialog.h"

#include <QDockWidget>
#include <QPushButton>
#include <QToolBar>
#include <QAction>
#include <QDebug>
#include <QModelIndex>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent)
{
    resize(600, 500);

    // Create common actions
    QAction *newTaskAction = new QAction(tr("Add &new task"), this);

    // Top toolbar
    QToolBar *topBar = new QToolBar(tr("Tools"));
    addToolBar(Qt::TopToolBarArea, topBar);
    topBar->setMovable(false);
    topBar->addAction(newTaskAction);
    topBar->addSeparator();

    setWindowTitle(tr("Download'em all"));
    downloadView = new DownloadView(this);
    setCentralWidget(downloadView);

    // Connections
    connect(newTaskAction, SIGNAL(triggered()),
            this, SLOT(addTask()));
}

void MainWindow::addTask() {
    NewTaskDialog* dialog = new NewTaskDialog();
    if(dialog->exec()) {
        downloadView->insertNewTask(dialog->getTask());
    }
}
